package com.hngates.architecture.controller;

import java.util.List;

import com.hngates.architecture.domain.*;
import com.hngates.architecture.service.*;
import com.hngates.common.constant.Constants;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hngates.common.annotation.Log;
import com.hngates.common.enums.BusinessType;
import com.hngates.common.core.controller.BaseController;
import com.hngates.common.core.domain.AjaxResult;
import com.hngates.common.utils.poi.ExcelUtil;
import com.hngates.common.core.page.TableDataInfo;

/**
 * 劳务合同Controller
 * 
 * @author jwhe
 * @date 2022-07-04
 */
@Controller
@RequestMapping("/architecture/labourContract")
public class ArcLabourContractController extends BaseController
{
    private String prefix = "architecture/labourContract";

    @Autowired
    private IArcLabourContractService arcLabourContractService;
    @Autowired
    private IArcWorkerComplainService arcWorkerComplainService;
    @Autowired
    private IArcProjectService arcProjectService;
    @Autowired
    private IArcBuilderCompanyService arcBuilderCompanyService;
    @Autowired
    private IArcConstructContractService arcConstructContractService;
    @Autowired
    private IArcLabourCompanyService arcLabourCompanyService;

    @Autowired
    private IArcLabourSubCompanyService arcLabourSubCompanyService;
    @Autowired
    private IArcLabourSubCompanyDetailsService arcLabourSubCompanyDetailsService;
    @Autowired
    private IArcProjectBuilderRelService arcProjectBuilderRelService;

    @RequiresPermissions("architecture:labourContract:view")
    @GetMapping()
    public String labourContract(ModelMap modelMap)
    {
        ArcProject arcProject = new ArcProject();
        arcProject.setDelFlag(Constants.DEl_FLAG_0);
        List<ArcProject> arcProjects = arcProjectService.selectArcProjectList(arcProject);


        ArcLabourCompany arcLabourCompany = new ArcLabourCompany();
        arcLabourCompany.setDelFlag(Constants.DEl_FLAG_0);
        List<ArcLabourCompany> arcLabourCompanies = arcLabourCompanyService.selectArcLabourCompanyList(arcLabourCompany);

        ArcLabourSubCompany arcLabourSubCompany = new ArcLabourSubCompany();
        arcLabourSubCompany.setDelFlag(Constants.DEl_FLAG_0);
        List<ArcLabourSubCompany> arcLabourSubCompanies = arcLabourSubCompanyService.selectArcLabourSubCompanyList(arcLabourSubCompany);

        modelMap.put("projects", arcProjects);
        modelMap.put("labourSubs", arcLabourSubCompanies);
        modelMap.put("labours", arcLabourCompanies);
        return prefix + "/labourContract";
    }

    /**
     * 查询劳务合同列表
     */
    @RequiresPermissions("architecture:labourContract:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ArcLabourContract arcLabourContract)
    {
        startPage();
        List<ArcLabourContract> list = arcLabourContractService.selectArcLabourContractList(arcLabourContract);
        return getDataTable(list);
    }

    /**
     * 导出劳务合同列表
     */
    @RequiresPermissions("architecture:labourContract:export")
    @Log(title = "劳务合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ArcLabourContract arcLabourContract)
    {
        List<ArcLabourContract> list = arcLabourContractService.selectArcLabourContractList(arcLabourContract);
        ExcelUtil<ArcLabourContract> util = new ExcelUtil<ArcLabourContract>(ArcLabourContract.class);
        return util.exportExcel(list, "劳务合同数据");
    }

    /**
     * 新增劳务合同
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存劳务合同
     */
    @RequiresPermissions("architecture:labourContract:add")
    @Log(title = "劳务合同", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ArcLabourContract arcLabourContract)
    {
        return toAjax(arcLabourContractService.insertArcLabourContract(arcLabourContract));
    }

    /**
     * 修改劳务合同
     */
    @RequiresPermissions("architecture:labourContract:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ArcLabourContract arcLabourContract = arcLabourContractService.selectArcLabourContractById(id);
        mmap.put("arcLabourContract", arcLabourContract);
        return prefix + "/edit";
    }

    /**
     * 修改保存劳务合同
     */
    @RequiresPermissions("architecture:labourContract:edit")
    @Log(title = "劳务合同", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ArcLabourContract arcLabourContract)
    {
        return toAjax(arcLabourContractService.updateArcLabourContract(arcLabourContract));
    }

    /**
     * 删除劳务合同
     */
    @RequiresPermissions("architecture:labourContract:remove")
    @Log(title = "劳务合同", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(arcLabourContractService.deleteArcLabourContractByIds(ids));
    }
}
